package com.liuyh.demo.controller;

import com.liuyh.demo.dao.CustomerRespository;
import com.liuyh.demo.domain.Customer;
import io.swagger.annotations.Api;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@Api(tags = "客户管理")
@RestController
@RequestMapping("/customer/")
public class CustomerRestController {

    public  static  final Logger log = LoggerFactory.getLogger(CustomerRestController.class);

    @Autowired
    private CustomerRespository customerRespository;

    @PostMapping("/")
    public void save(@RequestBody Customer customer){
        customerRespository.save(customer);
    }

    @GetMapping("/{customerId}")
    public @ResponseBody Customer findCustomerById(@PathVariable("customerId") Long customerId){
        return customerRespository.findById(customerId).get();
    }

    @GetMapping("/getCustomerByName/{customerName}")
    public @ResponseBody Customer findCustomerByName(@PathVariable("customerName") String customerName){
        return customerRespository.findCustomerByCustomerName(customerName);
    }

    @GetMapping("/getCustomerByName2/{customerName}")
    public @ResponseBody Customer findCustomerByName2(@PathVariable("customerName") String customerName){
        log.debug("customerName " + customerName);
        Customer customer = customerRespository.findCustomerByNameInput(customerName);
        log.debug("customer "+ customer);
        return customer;
    }

}
